package com.jj.service;


import com.jj.client.UserClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

@Service
public class UserService {

    @Autowired
    private UserClient userClient;

    public String getInfo(String name, int age) {
        return userClient.getInfo(name,age);
    }

    @HystrixCollapser(
            batchMethod = "getInfoByIdList",
            scope = com.netflix.hystrix.HystrixCollapser.Scope.GLOBAL
    )
    public Future<String> getInfoById(Integer id) {
        System.out.println("UserService中的getInfoById方法："+id);
        return new CompletableFuture<String>( );
    }

    @HystrixCommand
    public List<String> getInfoByIdList(List<Integer> idList) {
        System.out.println("UserService中的getInfoByIdList方法："+idList);
        return new ArrayList<String>(){};
    }
}
